#include "cnmainwindow.h"

cnMainWindow::cnMainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    if (this->objectName().isEmpty())
        this->setObjectName(QString::fromUtf8("this"));
    this->resize(800, 600);
    cnActionNew = new QAction(this);
    cnActionNew->setObjectName(QString::fromUtf8("cnActionNew"));
    cnActionConnect = new QAction(this);
    cnActionConnect->setObjectName(QString::fromUtf8("cnActionConnect"));
    cnActionCreate = new QAction(this);
    cnActionCreate->setObjectName(QString::fromUtf8("cnActionCreate"));
    cnActionLoad = new QAction(this);
    cnActionLoad->setObjectName(QString::fromUtf8("cnActionLoad"));
    cnActionSave = new QAction(this);
    cnActionSave->setObjectName(QString::fromUtf8("cnActionSave"));
    cnActionClose = new QAction(this);
    cnActionClose->setObjectName(QString::fromUtf8("cnActionClose"));
    cnActionQuit = new QAction(this);
    cnActionQuit->setObjectName(QString::fromUtf8("cnActionQuit"));
    cnActionPreferences = new QAction(this);
    cnActionPreferences->setObjectName(QString::fromUtf8("cnActionPreferences"));
    cnActionAbout = new QAction(this);
    cnActionAbout->setObjectName(QString::fromUtf8("cnActionAbout"));
    cnActionHelp = new QAction(this);
    cnActionHelp->setObjectName(QString::fromUtf8("cnActionHelp"));
    cnCentralWidget = new QWidget(this);
    cnCentralWidget->setObjectName(QString::fromUtf8("cnCentralWidget"));
    verticalLayout = new QVBoxLayout(cnCentralWidget);
    verticalLayout->setSpacing(0);
    verticalLayout->setContentsMargins(0, 0, 0, 0);
    verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
    verticalLayout->setSizeConstraint(QLayout::SetMinimumSize);
    cnGame = new cnGamePlan(cnCentralWidget);
    cnGame->setObjectName(QString::fromUtf8("cnGame"));
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(cnGame->sizePolicy().hasHeightForWidth());
    cnGame->setSizePolicy(sizePolicy);
    cnGame->setMinimumSize(QSize(800, 500));
    cnGame->setFrameShape(QFrame::StyledPanel);
    cnGame->setFrameShadow(QFrame::Raised);

    verticalLayout->addWidget(cnGame);

    cnGamePanel = new QHBoxLayout();
    cnGamePanel->setSpacing(3);
    cnGamePanel->setObjectName(QString::fromUtf8("cnGamePanel"));
    cnGamePanel->setSizeConstraint(QLayout::SetMaximumSize);
    cnGameDice = new QLabel(cnCentralWidget);
    cnGameDice->setObjectName(QString::fromUtf8("cnGameDice"));
    QSizePolicy sizePolicy1(QSizePolicy::Maximum, QSizePolicy::Maximum);
    sizePolicy1.setHorizontalStretch(0);
    sizePolicy1.setVerticalStretch(0);
    sizePolicy1.setHeightForWidth(cnGameDice->sizePolicy().hasHeightForWidth());
    cnGameDice->setSizePolicy(sizePolicy1);
    cnGameDice->setMinimumSize(QSize(77, 77));
    cnGameDice->setMaximumSize(QSize(77, 77));
    cnGameDice->setPixmap(QPixmap(QString::fromUtf8("resources/policko_grey.png")));
    cnGameDice->setScaledContents(true);
    cnGameDice->setWordWrap(false);

    cnGamePanel->addWidget(cnGameDice);

    cnGameRoll = new QPushButton(cnCentralWidget);
    cnGameRoll->setObjectName(QString::fromUtf8("cnGameRoll"));
    sizePolicy1.setHeightForWidth(cnGameRoll->sizePolicy().hasHeightForWidth());
    cnGameRoll->setSizePolicy(sizePolicy1);
    cnGameRoll->setMinimumSize(QSize(77, 77));
    cnGameRoll->setMaximumSize(QSize(77, 77));

    cnGamePanel->addWidget(cnGameRoll);

    cnGameSkip = new QPushButton(cnCentralWidget);
    cnGameSkip->setObjectName(QString::fromUtf8("cnGameSkip"));
    sizePolicy1.setHeightForWidth(cnGameSkip->sizePolicy().hasHeightForWidth());
    cnGameSkip->setSizePolicy(sizePolicy1);
    cnGameSkip->setMinimumSize(QSize(77, 77));
    cnGameSkip->setMaximumSize(QSize(77, 77));

    cnGamePanel->addWidget(cnGameSkip);

    cnGameList = new QListView(cnCentralWidget);
    cnGameList->setObjectName(QString::fromUtf8("cnGameList"));
    QSizePolicy sizePolicy2(QSizePolicy::Expanding, QSizePolicy::Maximum);
    sizePolicy2.setHorizontalStretch(0);
    sizePolicy2.setVerticalStretch(0);
    sizePolicy2.setHeightForWidth(cnGameList->sizePolicy().hasHeightForWidth());
    cnGameList->setSizePolicy(sizePolicy2);
    cnGameList->setMinimumSize(QSize(0, 0));
    cnGameList->setMaximumSize(QSize(16777215, 77));

    cnGamePanel->addWidget(cnGameList);


    verticalLayout->addLayout(cnGamePanel);

    this->setCentralWidget(cnCentralWidget);
    cnMenuBar = new QMenuBar(this);
    cnMenuBar->setObjectName(QString::fromUtf8("cnMenuBar"));
    cnMenuBar->setGeometry(QRect(0, 0, 800, 21));
    cnMenuBar->setNativeMenuBar(false);
    cnMenuFile = new QMenu(cnMenuBar);
    cnMenuFile->setObjectName(QString::fromUtf8("cnMenuFile"));
    cnMenuSettings = new QMenu(cnMenuBar);
    cnMenuSettings->setObjectName(QString::fromUtf8("cnMenuSettings"));
    cnMenuHelp = new QMenu(cnMenuBar);
    cnMenuHelp->setObjectName(QString::fromUtf8("cnMenuHelp"));
    this->setMenuBar(cnMenuBar);

    cnMenuBar->addAction(cnMenuFile->menuAction());
    cnMenuBar->addAction(cnMenuSettings->menuAction());
    cnMenuBar->addAction(cnMenuHelp->menuAction());
    cnMenuFile->addAction(cnActionNew);
    cnMenuFile->addAction(cnActionConnect);
    cnMenuFile->addAction(cnActionCreate);
    cnMenuFile->addSeparator();
    cnMenuFile->addAction(cnActionLoad);
    cnMenuFile->addAction(cnActionSave);
    cnMenuFile->addSeparator();
    cnMenuFile->addAction(cnActionClose);
    cnMenuFile->addSeparator();
    cnMenuFile->addAction(cnActionQuit);
    cnMenuSettings->addAction(cnActionPreferences);
    cnMenuHelp->addAction(cnActionAbout);
    cnMenuHelp->addSeparator();
    cnMenuHelp->addAction(cnActionHelp);

    this->setWindowTitle(QApplication::translate("this", "MainWindow", 0, QApplication::UnicodeUTF8));
    cnActionNew->setText(QApplication::translate("this", "New", 0, QApplication::UnicodeUTF8));
    cnActionConnect->setText(QApplication::translate("this", "Connect", 0, QApplication::UnicodeUTF8));
    cnActionCreate->setText(QApplication::translate("this", "Create", 0, QApplication::UnicodeUTF8));
    cnActionLoad->setText(QApplication::translate("this", "Load", 0, QApplication::UnicodeUTF8));
    cnActionSave->setText(QApplication::translate("this", "Save", 0, QApplication::UnicodeUTF8));
    cnActionClose->setText(QApplication::translate("this", "Close", 0, QApplication::UnicodeUTF8));
    cnActionQuit->setText(QApplication::translate("this", "Quit", 0, QApplication::UnicodeUTF8));
    cnActionPreferences->setText(QApplication::translate("this", "Preferences", 0, QApplication::UnicodeUTF8));
    cnActionAbout->setText(QApplication::translate("this", "About", 0, QApplication::UnicodeUTF8));
    cnActionHelp->setText(QApplication::translate("this", "Help", 0, QApplication::UnicodeUTF8));
    cnGameDice->setText(QString());
    cnGameRoll->setText(QApplication::translate("this", "Roll", 0, QApplication::UnicodeUTF8));
    cnGameSkip->setText(QApplication::translate("this", "Skip", 0, QApplication::UnicodeUTF8));
    cnMenuFile->setTitle(QApplication::translate("this", "File", 0, QApplication::UnicodeUTF8));
    cnMenuSettings->setTitle(QApplication::translate("this", "Settings", 0, QApplication::UnicodeUTF8));
    cnMenuHelp->setTitle(QApplication::translate("this", "Help", 0, QApplication::UnicodeUTF8));

    cnNew = new cnNewDialog(this);
    QObject::connect(cnActionNew,SIGNAL(triggered()),cnNew,SLOT(show()));
    QObject::connect(cnActionNew,SIGNAL(triggered(bool)),this,SLOT(setEnabled(bool)));
    QObject::connect(cnNew->cnNewOk,SIGNAL(clicked()),this,SLOT(create_new()));

    //cnGame = new cnGamePlan(cnCentralWidget);
    cnRandomInit();

    QMetaObject::connectSlotsByName(this);


}

void cnMainWindow::create_new()
{
    delete cnGame;
    cnGame = new cnGamePlan(cnCentralWidget);
    cnGame->setObjectName(QString::fromUtf8("cnGame"));
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(cnGame->sizePolicy().hasHeightForWidth());
    cnGame->setSizePolicy(sizePolicy);
    cnGame->setMinimumSize(QSize(800, 500));
    cnGame->setFrameShape(QFrame::StyledPanel);
    cnGame->setFrameShadow(QFrame::Raised);
    cnGame->setGeometry(0,0,this->width(),this->height() - 100);
    char *p = cnRandomPattern(cnNew->cnNewSize->value());
    cnGame->generate(cnNew->cnNewSize->value(),cnGame->width(),cnGame->height(),p);
    delete p;
    cnGame->setPlayers(cnNew->cnNewCount->value(),cnNew->cnNewColor->currentIndex());
    verticalLayout->insertWidget(0,cnGame);
}
